package com.mcptt.config.model;

import com.cloudptt.api.product.log.Log;
import com.mcptt.comm.CommonFunc;
import com.mcptt.db.model.AddrInfo;
import com.mcptt.db.model.UserInfo;

import android.os.Parcel;
import android.os.Parcelable;

public class McIdInfo implements Parcelable
{
	private static final String TAG = "McIdInfo";
	public static final String KEY = "mcIdInfo";
	public static final int TYPE_INTEL = 1;
	public static final int TYPE_FUNC = 0;
	private int type = TYPE_INTEL;
	private String mcId = null;
	private String pwd = null;

	private String clientId = null;
	private String userId = null;
	private String name = null;
	private String num = null;

	public McIdInfo(int type,String mcId,String pwd)
	{
		Log.d(TAG, "McIdInfo new");
		this.type = type;
		this.mcId = mcId;
		this.pwd = pwd;
		this.clientId = CommonFunc.getDateAndTimeSSS();
	}

	public void updateMcIdInfo(int type,String mcId,String pwd)
	{
		Log.d(TAG, "updateMcIdInfo type = " + type);
		this.type = type;
		this.mcId = mcId;
		this.pwd = pwd;
	}

	public void updateName(String name)
	{
		this.name = name;
	}
	public void update(String name,String num)
	{
		this.name = name;
		this.num = num;
	}

	public boolean isSameOne(String mcId,String pwd)
	{
		if(this.mcId.equals(mcId)
				&& this.pwd.equals(pwd))
		{
			return true;
		}
		return false;
	}

	public boolean isDac()
	{
		Log.d(TAG, "isDac mcId = " + mcId);
		if(this.mcId.equals("88000"))
		{
			return true;
		}
		return false;
	}

	public boolean isInvalid()
	{
		Log.d(TAG, "isInvalid McIdInfo = " + this);
		if(this.name == null
				|| this.name.length() <= 0)
		{
			return true;
		}
		return false;
	}

	public boolean isSameOne(String oldMcId)
	{
		if(this.mcId.equals(oldMcId))
		{
			return true;
		}
		return false;
	}

	public boolean isLogined()
	{
		if(this.name == null
				|| this.name.length() <= 0)
		{
			return true;
		}
		return false;
	}

	//	public UserInfo toUserInfo()
//	{
//		return new UserInfo(name,mcpttId,mcvideoId,mcdataId);
//	}
	public int getType() {
		return type;
	}
	public String getMcId()
	{
		return mcId;
	}
	public String getPwd()
	{
		return pwd;
	}

	public String getClientId() {
		return clientId;
	}
	public String getName() {
		return name;
	}

	public AddrInfo toAddrInfo()
	{
		AddrInfo info = new AddrInfo(AddrInfo.UserType_User,name,mcId,0);
		return info;
	}

	public UserInfo toUserInfo()
	{
		UserInfo info = new UserInfo(mcId,name);
		return info;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getNum() {
		return num;
	}

	public String toString()
	{
		StringBuffer buffer = new StringBuffer("IdInfo:");
		buffer.append("name = ").append(name).append(",");
		buffer.append("num = ").append(num).append(",");
		buffer.append("userId = ").append(userId).append(",");
		buffer.append("id = ").append(mcId).append(";");
		buffer.append("type = ").append(type).append(";");

		return buffer.toString();
	}

	public static final Parcelable.Creator<McIdInfo> CREATOR = new Parcelable.Creator<McIdInfo>() {
		public McIdInfo createFromParcel(Parcel in) {
			return new McIdInfo(in);
		}

		public McIdInfo[] newArray(int size) {
			return new McIdInfo[size];
		}
	};

	private McIdInfo(Parcel in)
	{
		type = in.readInt();
		mcId = getReadParcelableString(in.readString());
		pwd = getReadParcelableString(in.readString());
		name = getReadParcelableString(in.readString());
	}

	private String getWriteParcelableString(String str) {
		return (str == null) ? "null" : str;
	}
	private String getReadParcelableString(String str) {
		return str.equalsIgnoreCase("null") ? null : str;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeInt(type);
		dest.writeString(getWriteParcelableString(mcId));
		dest.writeString(getWriteParcelableString(pwd));
		dest.writeString(getWriteParcelableString(name));
	}
}
